public class LinkedNodeTest01 {
    //合并两个有序链表，合并为一个新的有序链表
    public LinkedNodeTest.LinkedNode mergeTwoLinked(LinkedNodeTest.LinkedNode head1, LinkedNodeTest.LinkedNode head2) {
        LinkedNodeTest.LinkedNode newNode = new LinkedNodeTest.LinkedNode(-1);//标注一个虚拟节点
        LinkedNodeTest.LinkedNode tempNode = newNode;
        while (head1 != null && head2 != null) {
            if (head1.val < head2.val) {
                newNode.next = head1;
                tempNode = newNode;
            } else {
                newNode.next = head2;
                tempNode = newNode;
            }
        }
        while (head1 != null && head2 != null) {
            if (head1.val < head2.val) {
                tempNode.next = head1;
                tempNode = head1;
                head1 = head1.next;
            }else {
                tempNode.next = head2;
                tempNode = head2;
                head2 = head2.next;
            }
        }
        if (head1 != null) {
            tempNode.next = head1;
        }
        if (head2 != null) {
            tempNode.next = head2;
        }
        return newNode.next;
    }

}
